< previous page page_378 next page >

Page 378
Selecting a fixed level of magnification
Adjusting a selected world window
Selecting a constrained region
Once you know the new world window boundaries, create a new mapping from the world window into the viewport using the viewport's scale properties. Then erase the old picture and redraw it. If your picture drawing commands are invoked in the viewport control's Paint event handler, you can do this by calling the viewport's Refresh method. This method forces an immediate repaint of the entire control.
Zooming Out
To zoom out, let the user select a new level of magnification from a menu. Create a Magnify 1/2 command to decrease the level of magnification by a factor of 1/2. Similarly, the commands Magnify 1/4, Magnify 1/8, and so forth allow faster decreases in the level of magnification. You can also implement a Full Scale command that immediately brings the program back to a default scale that shows the entire picture.
At this point, you might want to restrict the possible level of magnification. If you allow the user to decrease the level of magnification indefinitely, the picture will eventually become a dot in the middle of the screen. To prevent this, you can calculate a minimum allowed level of magnification. This should also be the magnification level given by the Full Scale command.
Make this minimum level of magnification small enough that the user can display a margin of empty space around the picture. Not only is this aesthetically pleasing, but it gives the user some confidence that the entire picture is visible. If your picture is not too complicated, allow a 10 percent margin around each edge. If your picture is very densely packed with lines, a 5 percent margin will do. When an empty margin is visible around a complex picture, it is easy to understand that the whole picture is visible.
Once you have computed the world window's new size, you can center it over its previous position. At this point, the world window may be so far to one side that it displays a lot of space beyond the edge of the picture. Figure 12.6 shows a world window before and after the level of magnification was decreased by a factor of 1/4. Because the old world window was close to the left edge of the picture, the new one extends far beyond the edge of the drawing.
In this case you can move the world window so that it no longer extends beyond the margins you have set for your picture. In Figure 12.6 you would move the world window to the right so that it contains less empty space.
If the aspect ratio of the area containing your complete picture in world coordinates does not match the aspect ratio of your viewport, the user must be able to display some empty space. If the picture is tall and thin and the viewport is relatively short and wide, the program must display a lot of empty space if it is to show the user all of the data at once. Figure 12.7 shows this situation.

 
< previous page page_378 next page >